package com.backend.system.controller;


import com.backend.system.beans.DeleteReq;
import com.backend.system.beans.menu.*;
import com.backend.system.common.ResponseEntity;
import com.backend.system.service.IMenuService;
import com.backend.system.service.manage.MenuManage;
import com.backend.system.util.ResponseUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * <p>
 * 菜单表 前端控制器
 * </p>
 *
 * @author backend-manage
 * @since 2024-04-02
 */
@Api(tags = "菜单表 前端控制器")
@RestController
@RequestMapping("/sys/menu")
public class MenuController {

    @Resource
    private IMenuService menuService;

    /**
     * 新增或修改菜单
     */
    @ApiOperation("新增或修改菜单")
    @PostMapping("/addOrUpdate")
    public ResponseEntity<Boolean> addOrUpdate(@Valid @RequestBody MenuAddOrUpdateReq req) {
        return ResponseUtil.success(MenuManage.addOrUpdate(req));
    }


    /**
     * 删除菜单
     */
    @ApiOperation("删除菜单")
    @PostMapping("/delete")
    public ResponseEntity<Boolean> delete(@Valid @RequestBody DeleteReq req) {
        return ResponseUtil.success(MenuManage.delete(req));
    }


    /**
     * 给角色分配菜单
     */
    @ApiOperation("给角色分配菜单")
    @PostMapping("/grantMenus")
    public ResponseEntity<Boolean> grantMenus(@Valid @RequestBody GrantMenusToRoleReq req) {
        return ResponseUtil.success(MenuManage.grantMenus(req));
    }

    /**
     * 启用或禁用菜单
     */
    @ApiOperation("启用或禁用菜单")
    @PostMapping("/disableOrEnable")
    public ResponseEntity<Boolean> disableOrEnable(@Valid @RequestBody MenuDisableOrEnableReq req) {
        return ResponseUtil.success(MenuManage.disableOrEnable(req));
    }

    /**
     * 按角色查询全部未禁用菜单（标识已拥有、未拥有）
     */
    @ApiOperation("按角色查询全部未禁用菜单（标识已拥有、未拥有）")
    @PostMapping("/listMenuByRole")
    public ResponseEntity<ListMenuByRoleVO> listMenuByRole(@Valid @RequestBody ListMenuByRoleReq req) {
        return ResponseUtil.success(menuService.listMenuByRole(req));
    }
}
